<template>
  <el-dialog class="set_dialog" width="500px" title="商品租赁频道" :visible.sync="dialogVisible" :close-on-click-modal="false">
    <el-form ref="refForm" class="ruleForm" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="租赁商品ID" prop="goodsLeaseId">
        <el-input v-model="form.goods_lease_id" />
      </el-form-item>
      <el-form-item label="租赁商品名称" prop="goodsLeaseTitle">
        <el-input v-model="form.goods_lease_title" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button size="small" type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { setLease } from '@/api/audit'
export default {
  //   props: ['goodsList'],
  props: {
    goodsList: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        goods_id: '',
        goods_lease_id: '',
        goods_lease_title: ''
      },
      dialogVisible: false,
      goodsId: null
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        for (const key in this.form) {
          if (key === 'goods_lease_id') {
            this.form[key] = this.goodsList.goods_lease_id
          } else if (key === 'goods_lease_title') {
            this.form[key] = this.goodsList.goods_lease_title
          } else if (key === 'goods_id') {
            this.form[key] = this.goodsList.id
          }
        }
      }
    }
  },
  methods: {
    submit() {
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          const params = {
            goods_lease_id: this.form.goods_lease_id,
            goods_lease_title: this.form.goods_lease_title,
            goods_id: this.goodsId
          }
          setLease(params).then(res => {
            this.dialogVisible = false
            this.$emit('getList', true)
          })
        } else {
          this.$message({
            message: '请检查表单错误',
            type: 'error'
          })
          return false
        }
      })
    }
  }
}

</script>

<style lang="scss" scoped>
.tip {
  line-height: 35px;
  margin-bottom: 10px;
}
</style>
